define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'bootstrap-table-jumpto'], function ($, undefined, Backend, Table, Form, Jump) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'cast/news/index' + location.search,
                    add_url: 'cast/news/add',
                    edit_url: 'cast/news/edit',
                    del_url: 'cast/news/del',
                    multi_url: 'cast/news/multi',
                    table: 'self_news',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,
                showJumpto: true,
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: '标题', operate: 'like', cellStyle:Controller.api.css.title},
                        {field: 'tag', title: '标签', visible:false, searchList:Config.tag},
                        {field: 'cate_name', title: '新闻分类', operate:false},

                        {field: 'imageUrls', title: __('Imageurls'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'url', title: __('Url'), formatter: Table.api.formatter.url, operate: false},
                        {field: 'likeCount', title: __('Likecount'), operate: false, sortable: true},
                        {field: 'commentCount', title: __('Commentcount'),operate: false,sortable: true},
                        {field: 'viewCount', title: __('Viewcount'), operate: false,sortable: true },
                        {field: 'publishDate', title: __('Publishdate'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            },
            css: {
                title: function () {
                    return {
                        css: {
                            'max-width': '350px',
                            'word-wrap': 'break-word',
                            'word-break': 'normal',
                            'max-height': '150px',
                            'display':'inline-block',
                            'overflow': 'hidden'
                        }
                    };
                }
            }
        }
    };
    return Controller;
});